package com.iyunsir.act.controller;


import com.iyunsir.act.entity.Act;
import com.iyunsir.common.vo.Result;
import com.iyunsir.act.service.ActService;
import com.iyunsir.act.vo.ActQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/act")
public class ActController {

    @Autowired

    private ActService actService;
    @GetMapping("")
    public String toActListUI(){
        return "actvip/actList";
    }

    @GetMapping("/list")
    @ResponseBody
    public Result<Object> getActList(ActQuery param){
        List<Act> list = actService.getActList(param);
        Long count = actService.countActList(param);
        return Result.success(list,count);

    }
    @PostMapping("")
    @ResponseBody
    public Result<Object> addAct(Act act){
        actService.addAct(act);
        return Result.success("新增活动成功");

    }
    @GetMapping("/add/ui")
    public String toAddUI(){

        return "actvip/actAdd";
    }
    @DeleteMapping("/{ids}")
    @ResponseBody
    public Result<Object> deleteActByIds(@PathVariable("ids") String ids){
        actService.deleteActByIds(ids);
        return Result.success("删除成功！");

    }
    @GetMapping("/{id}")
    public String getActById(@PathVariable("id") Integer id, Model model){
        Act act = actService.getActById(id);
        model.addAttribute("act",act);
        return "actvip/actEdit";
    }
    @PutMapping("")
    @ResponseBody
    public Result<Object> updateAct(Act act){
        actService.updateAct(act);
        return Result.success("活动信息修改成功!");

    }

}
